package com.bracelet.controller;

import com.bracelet.beans.Token;
import com.bracelet.beans.User;
import com.bracelet.utils.JWTUtils;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@Controller
public class Hello {

    @ResponseBody
    @RequestMapping(value="/hello",method = RequestMethod.POST)
    public Token hello(@Valid User user, BindingResult result, HttpServletRequest request){
        Token token1 = new Token();
        token1.getExtend().put("username","username");
        token1.setId(1);
        String tokenStr = JWTUtils.sign(token1,100000);
        System.out.println(tokenStr);
        Token token = JWTUtils.unsign(tokenStr, Token.class);
        return token;
    }
}